<?php

namespace App\Http\Controllers;

use App\Http\Requests\RegistRequest;
use App\Mail\RegistMail;
use App\User;
use Illuminate\Http\Request;
use Validator;
class RegisterController extends Controller
{
    //
    public function register(){
        return view('home.index.register');
    }
    public function store(Request $request,RegistRequest $registRequest){
        $post = $request->all();
//        dd($post);

        $post['password'] = bcrypt($post['password']);
        $post['email_token'] = str_random(10);
        $user = User::create($post);
        \Mail::to($user)->send(new RegistMail($user['email_token']));
        session()->flash('success','注册成功，请登录邮箱激活');
        return redirect('/login');

    }
    public function jihuo($token){
            $user = User::where('email_token','=',$token)->first();
            if($user){
                $user->status = 1;
                $user->save();
                \Auth::login($user);
                session()->flash('success','账号激活成功');
                return redirect('/index');
            }
            session()->flash('danger','账号不存在');
            return redirect('/login');
    }
}
